//
//  NSString+PLEncode.m
//  PlatformCommon
//
//  Created by KimmanYip on 2019/3/22.
//  Copyright © 2019 KimmanYip. All rights reserved.
//

#import "NSString+PLEncode.h"

@implementation NSString(PLEncode)

/**
 *  对字符串进行url编码
 */
- (NSString *)pl_urlEncode {
    return [self stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
}

/**
 *  对字符串进行url解码
 */
- (NSString *)pl_urlDecode {
    return [self stringByRemovingPercentEncoding];
}

/**
 base64编码
 */
- (NSString *)pl_base64Encode {
    NSData *data = [self dataUsingEncoding:NSUTF8StringEncoding];
    return [data base64EncodedStringWithOptions:0];
}

/**
 base64解码
 */
- (NSString *)pl_base64Decode {
    NSData *data = [[NSData alloc] initWithBase64EncodedString:self options:0];
    return [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
}
@end
